<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <link rel="shortcut icon" href="img/logo/rjh.ico" />
  <link rel="stylesheet" href="../css/common/bootstrap.min.css" />
  <title>领用收货单查询</title>
  <!--<script src="../js/common/vue.js"></script>-->
  <!--<script src="../js/common/element-ui.js"></script>-->
  <script src="../js/common/jquery.min.js"></script>
  <script src="../js/common/mustache.min.js"></script>
  <script>
    var getRootPath = function () {
      //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
      var curWwwPath = window.document.location.href;
      //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
      var pathName = window.document.location.pathname;
      var pos = curWwwPath.indexOf(pathName);
      //获取主机地址，如： http://localhost:8083
      var localhostPaht = curWwwPath.substring(0, pos);
      //获取带"/"的项目名，如：/uimcardprj
      var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
      return (localhostPaht + projectName + '/');
    };

    // 日期原型上增加 format 方法 date.format('yyyy-MM-dd') 返回 String
    Date.prototype.format = function (format) {
      var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
      };
      if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
          format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
            date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
      }
      return format;
    };

    //获取URL上的参数
    function GetQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    }
  </script>
</head>

<body>
  <div id="billQuery" style="width: 100%">
    <div style="padding: 20px;">
      <h2 style="text-align: center;">领用收货单查询</h2>
      <table class="table table-hover table-bordered table-striped">
        <thead>
          <th>领用单流水号</th>
          <th>物品代码</th>
          <th>物品名称</th>
          <th>批次流水号</th>
          <th>收货单单据号</th>
        </thead>
        <tbody id="tableBody">
        </tbody>
      </table>
    </div>
  </div>
  <script>
    window.onload = function onload() {
      var id = GetQueryString("id")
      if (id) {
        var tableBody$ = $('#tableBody')
        var str = '{{#data}}' +
          '<tr><td>{{领用单流水号}}</td>' +
          '<td>{{物品代码}}</td>' +
          '<td>{{物品名称}}</td>' +
          '<td>{{批次流水号}}</td>' +
          '<td>{{收货单单据号}}</td></tr>' +
          '{{/data}}'
        $.ajax({
          url: getRootPath() + '/api/billQuery',
          type: 'post',
          dataType: 'json',
          data: {
            id: id
          },
          success: function (data) {
            if (data.length > 0) {
              str = Mustache.render(str, {
                data: data
              })
              tableBody$.append(str)
            } else {
              alert('没有查询到数据')
            }
          }
        })
      } else {
        alert('没有查询到数据')
      }
    }
  </script>
</body>

</html>